<%@ page import="com.surelution.projects.crm.MarketGasSale" %>
<%@ page import="com.surelution.projects.crm.Market" %>
<%@ page import="com.surelution.projects.crm.OwnStation" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'market.label', default: 'Market')}" />
        <title><g:message code="default.list.label" args="[entityName]" /></title>
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
            <span class="menuButton"><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></span>
            <sec:ifAnyGranted roles="ROLE_ADMIN">
	            <span class="menuButton"><g:link class="create" action="marketImport"><g:message code="default.marketImport.label" /></g:link></span>
	 		    <span class="menuButton"><g:link class="export" action="export">${message(code: 'default.button.export.label', default: 'Export')}</g:link></span>
 		    </sec:ifAnyGranted>
        </div>
        <div class="body">
            <h1><g:message code="default.list.label" args="[entityName]" />(点击客户名称,可查看详情)</h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            
   		<sec:ifAnyGranted roles="ROLE_ADMIN">
             <g:form action="list" >
                <div class="dialog3">
                    <table>
                        <tbody>
                        	<tr class="prop">
                                <td valign="top" class="name">
                                    所属油站
                                </td>
                                <td valign="top" class="value">
                                	<g:select name="station.id" from="${OwnStation.list()}" optionKey="id" optionValue="shortName" noSelection='${["":""] }' value="${params['station.id'] }"/>
                                	<g:submitButton name="search" class="search" value="${message(code: 'default.button.search.label', default: 'Search')}" />
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </g:form>
           </sec:ifAnyGranted>
            <div class="list">
                <table>
                    <thead>
                        <tr>
                            <th style="color:white;font-size:12px;font-weight:bold;"><g:message code="market.marketType.label" /></th>

                            <th style="color:white;font-size:12px;font-weight:bold;"><g:message code="market.area.label" /></th>

                            <th style="color:white;font-size:12px;font-weight:bold;"><g:message code="market.name.label" /></th>

                            <th style="color:white;font-size:12px;font-weight:bold;"><g:message code="market.cardType.label" /></th>

                            <th style="color:white;font-size:12px;font-weight:bold;"><g:message code="market.station.label" /></th>

                            <th style="color:white;font-size:12px;font-weight:bold;"><g:message code="market.manager.label" /></th>

                            <th style="color:white;font-size:12px;font-weight:bold;"><g:message code="market.managerTel.label" /></th>

                            <th style="color:white;font-size:12px;font-weight:bold;"><g:message code="market.saleNumber.label"/></th>

                            <th style="color:white;font-size:12px;font-weight:bold;"><g:message code="market.dieselOilNumber.label"/></th>

                            <th style="color:white;font-size:12px;font-weight:bold;"><g:message code="market.annualSaleNumber.label" /></th>
                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${marketInstanceList}" status="i" var="marketInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                            <td>${fieldValue(bean: marketInstance, field: "marketType.type")}</td>

                            <td>${fieldValue(bean: marketInstance, field: "area.areaName")}</td>

                            <td><g:link action="show" id="${marketInstance.id}">${fieldValue(bean: marketInstance, field: "name")}</g:link></td>

                            <td>${marketInstance?.cardType}</td>
                        
                            <td style="text-align:center">${fieldValue(bean: marketInstance, field: "station.shortName")}</td>

                            <td style="text-align:center">${fieldValue(bean: marketInstance, field: "manager")}</td>

                            <td style="text-align:center">${fieldValue(bean: marketInstance, field: "managerTel")}</td>

                            <td><g:formatNumber number="${marketInstance?.annualGasAmount}" maxFractionDigits="3"/></td>

                            <td><g:formatNumber number="${marketInstance?.annualDieselAmount}" maxFractionDigits="3"/></td>

                            <td><g:formatNumber number="${marketInstance.annualSaleNumber}" maxFractionDigits="3"/></td>
                        </tr>
                    </g:each>
                    </tbody>
                </table>
            </div>
            <div class="paginateButtons">
                <g:paginate total="${marketInstanceTotal}" params="${params }"/>
            </div>

   			<sec:ifAnyGranted roles="ROLE_ADMIN">
	            <div style="height:500px;width:300px;padding-top:50px;">
					<img alt="chart" src="${grailsApplication.config.chartAPI.location}?chs=800x200&cht=bvs&chco=4d89f9&chxt=x,y&chxl=0:|0-5|5-10|10-15|15-20|20-25|25-30|30-35|35-40|40-45|45-50|50-55|55-60|60-65|65-70|70-75|75-80|85-90|90-95|95-100|${'(吨)'.encodeAsURL()}&chd=${marketSum}&chbh=30&chtt=${'客户分布图'.encodeAsURL()}">
	            </div>
            </sec:ifAnyGranted>
        </div>
    </body>
</html>
